import axios from './http';

// 获取可能所在城市
export const cityGuess=()=>{
    return axios.get('v1/cities',{
        params:{
            type: 'guess'
        }
    })
}
// 获取热门城市列表
export const hotCity=()=>{
    return axios.get('v1/cities',{
        params:{
            type: 'hot'
        }
    })
}
// 获取所有城市列表
export const groupcity=()=>{
    return axios.get('v1/cities',{
        params:{
            type: 'group'
        }
    })
}
// 根据城市ID获取城市信息
export const currentCity=(id)=>{
    return axios.get(`v1/cities/${id}`)
}
// 搜索城市地址信息
export const searchplace=(id,input)=>{
    return axios.get('/v1/pois',{
        params:{
            type: 'search',
            city_id: id,
            keyword: input
        }
    })
}
// 获取msite页面地址信息
export const msiteAddress = geohash => axios('/v2/pois/' + geohash);

// 获取msite页面食品分类列表
export const msiteFoodTypes = geohash => axios('/v2/index_entry', {
    params:{
        geohash,
        group_type: '1',
        'flags[]': 'F'
    }
});

// 获取mstie 商铺列表
export const shoplist=({latitude,longitude,offset=0,restaurant_category_id='',restaurant_category_ids='',order_by='',delivery_mode='',support_ids=[]}={})=>{
    // let supportStr='';
    // support_ids.for
    let params = {
        latitude,//纬度
        longitude,//经度
        offset,//跳过多少条数据，默认0
        limit:10,//请求数据的数量，默认20
        restaurant_category_id,//餐馆分类id
        order_by,//排序方式id： 1：起送价、2：配送速度、3:评分、4: 智能排序(默认)、5:距离最近、6:销量最高
        'delivery_mode[]':delivery_mode,//配送方式id
        'support_ids[]':support_ids,//餐馆支持特权的id
        'restaurant_category_ids[]':restaurant_category_ids//餐馆分类id
    }
    return axios.get('/shopping/restaurants',{
        params
    })
}

// food页面 左侧筛选- category分类
export const foodCategory = (latitude, longitude)=>axios.get('/shopping/v2/restaurant/category',{
    params:{
        latitude,
        longitude
    }
})
// 获取food页面的配送方式
export const foodDelivery = (latitude, longitude)=>axios.get('/shopping/v1/restaurants/delivery_modes',{
    params:{
        latitude,
        longitude,
        kw:''
    }
})
export const foodActivity = (latitude, longitude)=>axios.get('/shopping/v1/restaurants/activity_attributes',{
    params:{
        latitude,
        longitude,
        kw:''
    }
})

// 搜索 餐馆/美食
export const searchRestaurant = (geohash, keyword) => axios('/v4/restaurants', {
    params:{
        geohash,
        keyword
    }
}).then(res=>{
    if(res.status === 0){
        return [
            {
              name: "肯德基",
              address: "上海市宝山区淞宝路155弄18号星月国际商务广场1层",
              id: 1,
              latitude: 31.38098,
              longitude: 121.50146,
              location: [
                121.50146,
                31.38098
              ],
              phone: "1232313124324",
              category: "快餐便当/简餐",
              supports: [
                {
                  description: "已加入“外卖保”计划，食品安全有保障",
                  icon_color: "999999",
                  icon_name: "保",
                  id: 7,
                  name: "外卖保",
                  _id: "591bec73c2bbc84a6328a1e5"
                },
                {
                  description: "准时必达，超时秒赔",
                  icon_color: "57A9FF",
                  icon_name: "准",
                  id: 9,
                  name: "准时达",
                  _id: "591bec73c2bbc84a6328a1e4"
                },
                {
                  description: "该商家支持开发票，请在下单时填写好发票抬头",
                  icon_color: "999999",
                  icon_name: "票",
                  id: 4,
                  name: "开发票",
                  _id: "591bec73c2bbc84a6328a1e3"
                }
              ],
              status: 0,
              recent_order_num: 615,
              rating_count: 389,
              rating: 1.6,
              promotion_info: "他依然有人有人有人有人有人",
              piecewise_agent_fee: {
                tips: "配送费约¥5"
              },
              opening_hours: [
                "8:30/20:30"
              ],
              license: {
                catering_service_license_image: "",
                business_license_image: ""
              },
              is_new: true,
              is_premium: true,
              image_path: "/img/shop/15c1513a00615.jpg",
              identification: {
                registered_number: "",
                registered_address: "",
                operation_period: "",
                licenses_scope: "",
                licenses_number: "",
                licenses_date: "",
                legal_person: "",
                identificate_date: null,
                identificate_agency: "",
                company_name: ""
              },
              float_minimum_order_amount: 20,
              float_delivery_fee: 5,
              distance: "19.5公里",
              order_lead_time: "40分钟",
              description: "好吃的",
              delivery_mode: {
                color: "57A9FF",
                id: 1,
                is_solid: true,
                text: "蜂鸟专送"
              },
              activities: [
                {
                  icon_name: "减",
                  name: "满减优惠",
                  description: "满30减5，满60减8",
                  icon_color: "f07373",
                  id: 1,
                  _id: "591bec73c2bbc84a6328a1e7"
                },
                {
                  icon_name: "特",
                  name: "优惠大酬宾",
                  description: "是对冯绍峰的上市房地产",
                  icon_color: "EDC123",
                  id: 2,
                  _id: "591bec73c2bbc84a6328a1e6"
                }
              ],
            }
          ]
    }else{
        return res;
    }
});

// 获取验证码图片
export const getcaptchas=()=>axios.post('/v1/captchas');

// 密码登录
export const accountLogin = (username, password, captcha_code) => axios.post('/v2/login', {
    username, 
    password, 
    captcha_code
});

// 上传icon图片
export const uploadFileIcon = (uid,data)=>{
    return axios.post(`/eus/v1/users/${uid}/avatar`,data,{
        withCredentials:"true"
    })
}

// 
export const searchNearby = (kw)=>{
    return axios.get('/v1/pois',{
        params:{
            type: 'nearby',
            keyword:kw
        }
    })
}

// 添加地址
export const postAddAddress=(userId, address, address_detail, geohash, name, phone, phone_bk, poi_type, sex, tag, tag_type)=>axios.post('/v1/users/' + userId + '/addresses',{
    address,
	address_detail,
	geohash,
	name,
	phone,
	phone_bk,
	poi_type,
	sex,
	tag,
	tag_type,
})

//个人中心里编辑地址
export const getAddressList = (user_id) => axios.get('/v1/users/'+user_id+'/addresses')

//删除地址
export const deleteAddress=(userid, addressid)=>axios.delete('/v1/users/' + userid + '/addresses/' + addressid)

// 获取红包数
export const getHongbaoNum = id => axios.get('/promotion/v2/users/' + id + '/hongbaos?limit=20&offset=0');

// 获取过期红包
export const getExpired = id => axios.get('/promotion/v2/users/' + id + '/expired_hongbaos?limit=20&offset=0');

// 兑换红包
export const exChangeHongbao = (id,exchangeCode,code)=>axios.post('/v1/users/' + id + '/hongbao/exchange',{
    exchange_code:exchangeCode,
	captcha_code:code,
})

// 店铺详情
export const shopDetails = (id,latitude,longitude) => axios.get(`/shopping/restaurant/${id}`,{
    params:{
        latitude,
        longitude,
        'extras[]':'activities',
        'extras[]':'album',
        'extras[]':'license',
        'extras[]':'identification',
        'extras[]':'statistics'
    }
})

// 获取shop页面菜单列表
export const foodMenu = (id)=>axios.get('/shopping/v2/menu',{
    params:{
        restaurant_id:id
    }
})

// 获取商铺评价列表
export const getRatingList = (shopid, offset, tag_name = '') => axios.get('/ugc/v2/restaurants/' + shopid + '/ratings', {
	params:{
        has_content: true,
        offset,
        limit: 10,
        tag_name
    }
});
//获取商铺评价分数
export const ratingScores =  shopid => axios.get('/ugc/v2/restaurants/' + shopid + '/ratings/scores');
// 商铺评价分类
export const ratingTags = shopid => axios.get('/ugc/v2/restaurants/' + shopid + '/ratings/tags');

// 确认订单
export const checkout = (geohash,entities,shipId)=>axios.post('/v1/carts/checkout',{
    come_from: "web",
	geohash,
	entities,
	restaurant_id: shipId,
})


// 获取快速备注列表
export const getRemark = (id, sig) => axios.get('/v1/carts/' + id + '/remarks', {
    params:{
        sig
    }
});

//下订单
export const placeOrders = (user_id, cart_id, address_id, description, entities, geohash, sig) => axios.post('/v1/users/' + user_id + '/carts/' + cart_id + '/orders', {
   address_id,
   come_from: "mobile_web",
   deliver_time: "",
   description,
   entities,
   geohash,
   paymethod_id: 1,
   sig,
});

export const getService = () => axios.get('/v3/profile/explain');
